#include "task_pageManage.h"
#include "tasksInit.h"

#include "los_task.h"
#include "los_queue.h"
#include "los_event.h"



#include "bsp_key.h"
#include "bsp_led.h"

#include "ui.h"

unsigned int task_pageManage_id;
TSK_INIT_PARAM_S task_pageManage_handler = {
    (TSK_ENTRY_FUNC)task_pageManage,
    22,
    0,
    1024 * 40,
    "task_pageManage",
    0
};

ui_t miao_ui;

void task_pageManage()
{
    // int ret = 0;
    KEY_TYPE key = NOKEY_PRES;
    uint32_t dataSize = sizeof(key);

    LOS_EventRead(&bspInit_ECB, BSPINIT_EVENT_INITOK, LOS_WAITMODE_AND, LOS_WAIT_FOREVER);

    printf("[page manage] start MiaoUi_Setup\n");

    MiaoUi_Setup(&miao_ui);

    printf("[page manage] MiaoUi_Setup end\n");

    while(1)
    {
        key = NOKEY_PRES;

        //读队列
        LOS_QueueReadCopy(pageManage_qId, (void *)&key, &dataSize, 1);

        // printf("[page manage] key from queue = %d\n", key);
        switch(key)
        {
        case KEY2_PRES:
            led_toggle(LED2);
            break;
        case KEY1_PRES:
            led_toggle(LED1);
            break;

        case KEY4_PRES:
            // beep_toggle();
            led_toggle(LED1);
            led_toggle(LED2);
            break;
        default:
            break;
        }

        // if(key != 0)
        // {
        //     printf("[page manage] key from queue = %d\n", key);
        // }

        ui_loop(&miao_ui, key);

        LOS_Msleep(20);
    }
}

